from rest_framework import serializers
from rest_framework.serializers import ModelSerializer

from articles.models import Article, ArticlCategory


class ArticleCategoriesSerializer(ModelSerializer):
    class Meta:
        model = ArticlCategory
        fields = ('id','name','alias','is_delete')
        # fields = '__all__'
        extra_kwargs={
            'is_delete':{
                'required':False
            }
        }

class ArticleSerializer(ModelSerializer):
    cate_name =serializers.StringRelatedField()
    cate_name_id = serializers.CharField()
    class Meta:
        model = Article
        fields = '__all__'
        # fields = ('id','title','pub_date','state','cate_name','cate_name_id')
        # read_only_fields = ('cate_name',)
        write_only_fields = ('cate_name_id','author_id','create_time','update_time','content','author_id','cover_img','author')








